#include "URL.h"
#include <iostream>
#include <list>
#include "URLFileDealer.h"

using namespace std;
using namespace __gnu_cxx;

std::auto_ptr<URLFileDealer> URLFileDealer::theURLFileDealer;

URLFileDealer &URLFileDealer::getInstance()
{
	//Cuidado no multithreading...
    if(theURLFileDealer.get() == 0)
    	theURLFileDealer.reset(new URLFileDealer);
    return *theURLFileDealer;
}

//esse metodo vai pro repositorio(?)
list<URL> URLFileDealer::getVisitedURLs() {
	listURL urlList;
	return urlList;
}

void URLFileDealer::initURLHashMap(){
	string urlHash;
	string urlString;
	URLFileDealer theURLFileDealer = URLFileDealer::getInstance();
	list<URL> * visitedURLList = theURLFileDealer.getVisitedURLs();
	list<URL>::iterator it;
	for (it = visitedURLList->begin(); it!=visitedURLList->end(); it++){
		urlString = it->get_protocol() + it->get_dominio() + it->get_path();
		urlHash = Hasher::md5(urlString);
		urlHashMap[urlHash] = urlString;
	}
}

list<URL> URLFileDealer::getNewURLs(int quantity) {
	URL temp;
	list<URL> urlList;
	temp = URL("www.uol.com.br", "inicio.html", "http://");
	urlList.push_back(temp);
	temp = URL("www.terra.com.br", "pasta1/arquivo.php", "http://");
	urlList.push_back(temp);
	temp = URL("www.uol.com.br", "pasta1/pasta2/arquivo.html", "http://");
	urlList.push_back(temp);
	return urlList;
}